<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="baTable.form.operate ? true : false"
        @close="baTable.toggleForm"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                    :disabled="baTable.form.operate =='view'"
                    class="flex"
                >
                <FormItem :label="t('xPOTSTATUS.TCNO')" 
                v-model="baTable.form.items!.TCNO" 
                prop="TCNO" 
                type="remoteSelect"
                :input-attr="{
                    pk: 'TCNO',
                    field: 'TCNO',
                    'remote-url': '/admin/XPot/index?search[]=%7B%22field%22:%22STATUS%22,%22val%22:%22SYZ%22,%22operator%22:%22%3D%22%7D',
                }" 
                />
                <FormItem :label="'罐箱种类'" type="string" v-model="baTable.form.items!.CODENAME" prop="CODENAME" :input-attr="{ placeholder: '自动关联罐箱',disabled:true }" />
                <FormItem :label="t('xPOTSTATUS.STATUS')" 
                v-model="baTable.form.items!.STATUS" 
                prop="STATUS" 
                type="remoteSelect"
                :input-attr="{
                    pk: 'codename',
                    field: 'codename',
                    'remote-url': codelib  + 'now?where=potyystatus',
                }"  
                />
                <FormItem :label="t('xPOTSTATUS.YARD')" 
                v-model="baTable.form.items!.YARD" 
                prop="YARD" 
                type="remoteSelect"
                :input-attr="{
                    pk: 'CORP',
                    field: 'CORP',
                    'remote-url': '/admin/corplib/index?type=2',
                }" 
                />
                <FormItem :label="t('xPOTSTATUS.INDATE')" type="datetime" v-model="baTable.form.items!.INDATE" prop="INDATE" :input-attr="{ placeholder: t('Please select field', { field: t('xPOTSTATUS.INDATE') }) }" />
                <FormItem :label="t('xPOTSTATUS.OUTDATE')" type="datetime" v-model="baTable.form.items!.OUTDATE" prop="OUTDATE" :input-attr="{ placeholder: t('Please select field', { field: t('xPOTSTATUS.OUTDATE') }) }" />
                <FormItem :label="t('xPOTSTATUS.CLEANSTART')" type="datetime" v-model="baTable.form.items!.CLEANSTART" prop="CLEANSTART" :input-attr="{ placeholder: t('Please select field', { field: t('xPOTSTATUS.CLEANSTART') }) }" />
                <FormItem :label="t('xPOTSTATUS.CLEANEND')" type="datetime" v-model="baTable.form.items!.CLEANEND" prop="CLEANEND" :input-attr="{ placeholder: t('Please select field', { field: t('xPOTSTATUS.CLEANEND') }) }" />
                <FormItem :label="t('xPOTSTATUS.REPAIRSTART')" type="datetime" v-model="baTable.form.items!.REPAIRSTART" prop="REPAIRSTART" :input-attr="{ placeholder: t('Please select field', { field: t('xPOTSTATUS.REPAIRSTART') }) }" />
                <FormItem :label="t('xPOTSTATUS.REPAIREND')" type="datetime" v-model="baTable.form.items!.REPAIREND" prop="REPAIREND" :input-attr="{ placeholder: t('Please select field', { field: t('xPOTSTATUS.REPAIREND') }) }" />
                <FormItem :label="t('xPOTSTATUS.KTXTIME')" type="datetime" v-model="baTable.form.items!.KTXTIME" prop="KTXTIME" :input-attr="{ placeholder: t('Please select field', { field: t('xPOTSTATUS.KTXTIME') }) }" />
                <!-- <FormItem :label="t('xPOTSTATUS.DRFLAG')" type="string" v-model="baTable.form.items!.DRFLAG" prop="DRFLAG" :input-attr="{ placeholder: t('Please input field', { field: t('xPOTSTATUS.DRFLAG') }) }" /> -->
                <!-- <FormItem :label="t('xPOTSTATUS.ACTIVE')" type="string" v-model="baTable.form.items!.ACTIVE" prop="ACTIVE" :input-attr="{ placeholder: t('Please input field', { field: t('xPOTSTATUS.ACTIVE') }) }" /> -->
                <FormItem :label="t('xPOTSTATUS.OP')" type="string" v-model="baTable.form.items!.OP" prop="OP" :input-attr="{ placeholder: '当前登录人',disabled:true }" />
                <FormItem :label="t('xPOTSTATUS.OPTIME')" type="datetime" v-model="baTable.form.items!.OPTIME" prop="OPTIME" :input-attr="{ placeholder: '当前时间',disabled:true }" />
                <FormItem :label="t('xPOTSTATUS.REMARK')" style="width:100%" type="textarea" v-model="baTable.form.items!.REMARK" prop="REMARK" :input-attr="{ placeholder: t('Please input field', { field: t('xPOTSTATUS.REMARK') }) }" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer v-if="baTable.form.operate !=='view'">
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { ElForm, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'
import { codelib } from '/@/api/controllerUrls'


const formRef = ref<InstanceType<typeof ElForm>>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    INDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.INDATE') })})],
    OUTDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.OUTDATE') })})],
    CLEANSTART: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.CLEANSTART') })})],
    CLEANEND: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.CLEANEND') })})],
    REPAIRSTART: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.REPAIRSTART') })})],
    REPAIREND: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.REPAIREND') })})],
    KTXTIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.KTXTIME') })})],
    OPTIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xPOTSTATUS.OPTIME') })})],
})

</script>

<style scoped lang="scss"></style>
